package com.zhijiang.util;


// CryptoJS前端加密后台Java解密
public class DesCipherUtil {

    //private static String KEY = "fxkcfxkcfxkcfxkc";
    //
    //
    //
    //public static String decrypt(String encryptedText) throws Exception {
    //    SecretKeySpec secretKey = new SecretKeySpec(KEY.getBytes("UTF-8"), "AES");
    //    Cipher cipher = Cipher.getInstance("AES/ECB/PKCS5PADDING");
    //    cipher.init(Cipher.DECRYPT_MODE, secretKey);
    //    byte[] encryptedBytes = Base64.decodeBase64(encryptedText.getBytes("UTF-8"));
    //    byte[] decryptedBytes = cipher.doFinal(encryptedBytes);
    //    String decryptedText = new String(decryptedBytes);
    //    System.out.println(decryptedText);
    //    return decryptedText;
    //}
    //private static final String CIPHER_ALGORITHM = "AES/ECB/PKCS5Padding";
    //private static final String KEY_ALGORITHM = "AES";
    //
    ///**
    // * 解密
    // * @param data 密文
    // * @param key 密钥
    // * @return 明文
    // * @throws Exception
    // */
    //
    //public static String decrypt1(String data, String key) throws Exception {
    //    key="fxkcfxkcfxkcfxkcfxkc";
    //    byte[] encryptedBytes = Base64.decodeBase64(data);
    //    byte[] keyBytes = Base64.decodeBase64(key);
    //
    //    SecretKeySpec secretKeySpec = new SecretKeySpec(keyBytes, KEY_ALGORITHM);
    //
    //    Cipher cipher = Cipher.getInstance(CIPHER_ALGORITHM);
    //    cipher.init(Cipher.DECRYPT_MODE, secretKeySpec);
    //
    //    byte[] decryptedBytes = cipher.doFinal(encryptedBytes);
    //    return new String(decryptedBytes, "UTF-8");
    //}
    //
    //public static void main(String[] args) throws Exception {
    //    String s = DesCipherUtil.decrypt1("U2FsdGVkX18ajuxTuV5Cc+FvzYY0Runb8DcLJCnKhKI=", KEY);
    //
    //    System.out.println(s);
    //}
    //private static String desEncript(String clearText, String secretTest) throws Exception {
    //    //获取加密工具类
    //    Cipher cipher=Cipher.getInstance("DES");
    //    //对工具类进行初始化
    //    SecretKeySpec key=new SecretKeySpec(secretTest.getBytes(),"DES");
    //    cipher.init(Cipher.ENCRYPT_MODE,key);
    //    //用工具类对象对明文进行加密
    //    byte[] bytes = cipher.doFinal(clearText.getBytes());
    //    return new String(bytes);
    //}
    ///**编码格式*/
    //private static final String ENCODING = "UTF-8";
    ///**加密算法*/
    //public static final String KEY_ALGORITHM = "AES";
    ///**签名算法*/
    //public static final String SIGN_ALGORITHMS = "SHA1PRNG";
    //
    //public static String decrypt(String content, String key) {
    //             if (content.length() < 1) return null;
    //            byte[] byteRresult = new byte[content.length() / 2];
    //             for (int i = 0; i < content.length() / 2; i++) {
    //                     int high = Integer.parseInt(content.substring(i * 2, i * 2 + 1), 16);
    //                     int low = Integer.parseInt(content.substring(i * 2 + 1, i * 2 + 2), 16);
    //                     byteRresult[i] = (byte) (high * 16 + low);
    //                 }
    //             try {
    //                     KeyGenerator kgen = KeyGenerator.getInstance(KEY_ALGORITHM);
    //                     SecureRandom random = SecureRandom.getInstance(SIGN_ALGORITHMS);
    //                     random.setSeed(key.getBytes(ENCODING));
    //                     kgen.init(128, random);
    //                     SecretKey secretKey = kgen.generateKey();
    //                     byte[] enCodeFormat = secretKey.getEncoded();
    //                     SecretKeySpec secretKeySpec = new SecretKeySpec(enCodeFormat, KEY_ALGORITHM);
    //                     Cipher cipher = Cipher.getInstance(KEY_ALGORITHM);
    //                     cipher.init(Cipher.DECRYPT_MODE, secretKeySpec);
    //                     byte[] result = cipher.doFinal(byteRresult);
    //                     return new String(result, ENCODING);
    //                 } catch (Exception e) {
    //                     e.toString();
    //                 }
    //             return null;
    //         }
    //@Autowired
    //private PasswordEncoder passwordEncoder;
    //public static String test(String password){
    //    String encode = passwordEncoder.matches(password);
    //    System.out.println(encode);
    //    return encode;
    //}


    public static void main(String[] args) {

    }


}
